package com.mk.service.platform;

import act.controller.Controller;
import cn.hutool.core.date.DateUtil;
import com.github.d925529.apidoc.ApiHttpMethod;
import com.github.d925529.apidoc.annotation.*;
import com.mk.domain.ZBrand;
import com.mk.interceptor.ITranslate;
import com.mk.util.S2;
import org.osgl.mvc.annotation.GetAction;
import org.osgl.mvc.annotation.PostAction;
import org.osgl.mvc.annotation.PutAction;
import org.osgl.mvc.annotation.With;
import org.osgl.util.C;

import javax.inject.Inject;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 说明：品牌表后台服务
 * 作者：nwl 
 * 日期：2018-10-11 15:7:11 
 * 版本：1.0.0
 */
@Controller("zBrand")
@Api(group = "pl",title = "品牌表服务", path = "/zBrand")
@SuppressWarnings("unused")
public class ZBrandService extends BasePlatformService {
    @Inject
    private ZBrand.Mapper zBrandMapper;


    @With({ILogin.class, ITranslate.class})
    @PostAction("add.json")
    @ApiMethod(title = "增加保存品牌表", path = "/add.json", method = ApiHttpMethod.POST)
    @ApiParam(name = "zBrand", title = "品牌表", type = ZBrand.class)
    @ApiReturn(description = "主键", type = String.class)
    public String add(@NotNull ZBrand zBrand) {
        String id = S2.UUID();
        zBrand.setBrid(id);
        zBrand.setBrdate(DateUtil.now());
        zBrandMapper.insertTemplate(zBrand);
        return id;
    }


    @With({ILogin.class, ITranslate.class})
    @GetAction("findBra.json")
    @ApiMethod(title = "增加保存品牌表", path = "/findBra.json", method = ApiHttpMethod.POST)
    public List<ZBrand> findBra(String parent,String brid) {
        return zBrandMapper.getSQLManager().select("zBrand.select_list",ZBrand.class, C.Map("parent",parent,"pbrid",brid));
    }


    @With({ILogin.class, ITranslate.class})
    @PutAction("update.json")
    @ApiMethod(title = "修改保存品牌表", path = "/update.json", method = ApiHttpMethod.PUT)
    @ApiParam(name = "zBrand", title = "品牌表", type = ZBrand.class)
    @ApiReturn(description = "修改了的数量", type = int.class)
    public int update(@NotNull ZBrand zBrand) {
        return zBrandMapper.updateTemplateById(zBrand);
    }

    @With(ILogin.class)
    @GetAction("view.json")
    @ApiMethod(title = "查询指定品牌表", path = "/view.json", method = ApiHttpMethod.GET)
    @ApiParam(name = "id", title = "品牌表的主键", type = String.class)
    @ApiReturn(description = "品牌表", type = ZBrand.class)
    public ZBrand view(@NotNull String id){
        return zBrandMapper.single(id);
    }
}
